import type { EventBusListener } from "@vueuse/core";

export const useEventBusStore = defineStore("EventBus", () => {
  const eventBus = useEventBus<ValueOf<typeof EventMap>>("eventBus");
  const emit = (eventName: ValueOf<typeof EventMap>, paylod?: any) => {
    return eventBus.emit(eventName, paylod);
  };
  const on = (listener: EventBusListener<ValueOf<typeof EventMap>, any>) => {
    return eventBus.on(listener);
  };
  const off = (listener: EventBusListener<ValueOf<typeof EventMap>, any>) => {
    return eventBus.off(listener);
  };
  return { emit, on, eventBus, off };
});
